import Mock from 'mockjs';

const {list}=Mock.mock({
    'list|100':[
        {
            id:"@id",
            username:'@cname()',
            productLine:'产品' + '@integer(1,10)',
            bussines:  '行业' + '@integer(0,9)',
            creatTimes:"@date(yyyy-MM-dd hh:mm:ss)",
            interlligence:"@cword(5,9)",
            bussines2: '副业' + '@integer(0,9)',
            type:'@cword(2,4)',
            evaluate:'@cword(10,20)',
            url:'https://scpic.chinaz.net/files/pic/pic9/202009/apic27858.jpg',
            'data|1-10':[
             {
                dataID:"@increment()",
                title:"@ctitle(15,30)",
                describe:'@csentence(30,60)',
                img:["@image('300x200','@color()','#fff','png','!')","@image('300x200','@color()','#fff','png','!')"],
           
            }
            ]
        }
    ]
})

Mock.mock('/api/getDate','get',(options)=>{
    let params =JSON.parse(options.body)
    let newlist = [];
    let total = list.length;
    let filterlist =  list.filter(item => {
        let time = new Date(item.creatTimes).getTime();
        let s = 0;
        let e = new Date().getTime()
        if(params.startTimes || params.endTimes){
        if(params.startTimes)
         s = new Date(params.startTimes).getTime();
   
        if(params.endTimes)
         e = new Date(params.endTimes).getTime() ;
         return  (time <=e && time >= s)
        }

        return item.username == params.username || item.bussines == params.bussines || item.productLine == params.product 
    })
    if(filterlist.length == 0){
     newlist = list.slice(params.currentPage-1,params.currentPage+9);
     
    }else{
        newlist = filterlist.slice(params.currentPage-1,params.currentPage+9);
        total = filterlist.length
    }
    return {
        status:200,
        message:'获取成功！',
        total:total,
        list:newlist
    }
})

var nextID = ''

Mock.mock('/api/getDetail','get',(options)=>{
    let params =JSON.parse(options.body)
    let res = '';
        res = list.filter((item ,index) => {
      if(item.id == params.id)  nextID = index + 1
       return item.id == params.id
    })[0]
     if(params.next==true) res = list[nextID]
    return {
        status:200,
        message:'获取成功！',
        data:res
    }
})

